/* 	The first token of an AST
	From: Department of CSE
	Authors: Le Minh Vu, Nguyen Hua Phung
	Date: 15/11/2007
*/
package MP.staticchecker;
import MP.CompilationException;
import MP.ASTs.*;

public class LeftMostVisitor implements Visitor {
	public LeftMostVisitor() {
	}
	// ProgramAST
	public Object visitProgramAST(ProgramAST ast, Object o)
			throws CompilationException {
		Object ret = ast.v.visit(this,o);
		if (ret != null) return ret;
		ret = ast.p.visit(this,o);
		if (ret != null) return ret; 
		ret = ast.c.visit(this, o);
		return ret;
	}

	// VarDeclPartAST
	public Object visitVarDeclPartAST(VarDeclPartAST ast, Object o)
			throws CompilationException {
		return ast.o.visit(this, o);
	}

	// EmptyVarDeclPartAST
	public Object visitEmptyVarDeclPartAST(EmptyVarDeclPartAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// OneDeclAST
	public Object visitVarDeclAST(OneDeclAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// ConstDeclAST
	public Object visitConstDeclAST(OneDeclAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// ArrayTypeAST
	public Object visitArrayTypeAST(ArrayTypeAST ast, Object o)
			throws CompilationException {
		return ast.lower;
	}

	// EmptyExprListAST
	public Object visitEmptyExprListAST(EmptyExprListAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// ExprListAST
	public Object visitExprListAST(ExprListAST ast, Object o)
			throws CompilationException {
		return ast.e.visit(this, o);

	}

	// ProDeclPartAST
	public Object visitProDeclPartAST(ProDeclPartAST ast, Object o)
			throws CompilationException {
		return ast.o.visit(this, o);
	}

	// EmptyProDeclPartAST
	public Object visitEmptyProDeclPartAST(EmptyProDeclPartAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// FuncDeclAST
	public Object visitFuncDeclAST(FuncDeclAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// ProcDeclAST
	public Object visitProcDeclAST(ProcDeclAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// ParaListAST
	public Object visitParaListAST(ParaListAST ast, Object o)
			throws CompilationException {
		return ast.v.visit(this, o);
	}

	// EmptyParaListAST
	public Object visitEmptyParaListAST(EmptyParaListAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// BoolTypeAST
	public Object visitBoolTypeAST(BoolTypeAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// IntTypeAST
	public Object visitIntTypeAST(IntTypeAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// RealTypeAST
	public Object visitRealTypeAST(RealTypeAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// StmtListAST
	public Object visitStmtListAST(StmtListAST ast, Object o)
			throws CompilationException {
		return ast.o.visit(this, o);
	}

	// EmptyStmtListAST
	public Object visitEmptyStmtListAST(EmptyStmtListAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// OneStmtAST
	public Object visitAssiStmtAST(AssiStmtAST ast, Object o)
			throws CompilationException {
		return ast.l.visit(this, o);
	}

	// IfThenElseStmtAST
	public Object visitIfThenElseStmtAST(IfThenElseStmtAST ast, Object o)
			throws CompilationException {
		return ast.e.visit(this, o);
	}

	// IfThenStmtAST
	public Object visitIfThenStmtAST(IfThenStmtAST ast, Object o)
			throws CompilationException {
		return ast.e.visit(this, o);
	}

	// RepeatStmtAST
	public Object visitRepeatStmtAST(RepeatStmtAST ast, Object o)
			throws CompilationException {
		return ast.s.visit(this, o);
	}

	// RetNullStmtAST
	public Object visitRetNullStmtAST(RetNullStmtAST ast, Object o)
			throws CompilationException {
		return null;
	}

	// RetStmtAST
	public Object visitRetStmtAST(RetStmtAST ast, Object o)
			throws CompilationException {
		return ast.e.visit(this, o);
	}

	// CallStmtAST
	public Object visitCallStmtAST(CallStmtAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// ForStmtAST
	public Object visitForStmtAST(ForStmtAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// WhileStmtAST
	public Object visitWhileStmtAST(WhileStmtAST ast, Object o)
			throws CompilationException {
		return ast.e.visit(this, o);
	}

	// BreakStmtAST
	public Object visitBreakStmtAST(BreakStmtAST ast, Object o)
			throws CompilationException {
		return ast.brk;
	}

	// CompStatAST
	public Object visitCompStatAST(CompStatAST ast, Object o)
			throws CompilationException {
		Object ret = ast.v.visit(this, o);
		if (ret != null) return ret;
		ret = ast.s.visit(this, o);
		return ret;
	}

	// ContStmtAST
	public Object visitContStmtAST(ContStmtAST ast, Object o)
			throws CompilationException {
		return ast.con;
	}

	public Object visitLvalueAST(LvalueAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// LiteralAST
	public Object visitIntLiteralAST(IntLiteralAST ast, Object o)
			throws CompilationException {
		return ast.literal;
	}

	public Object visitRealLiteralAST(RealLiteralAST ast, Object o)
			throws CompilationException {
		return ast.literal;
	}

	public Object visitBoolLiteralAST(BoolLiteralAST ast, Object o)
			throws CompilationException {
		return ast.literal;
	}

	public Object visitStringLiteralAST(StringLiteralAST ast, Object o)
			throws CompilationException {
		return ast.literal;
	}

	// UnaryExprAST
	public Object visitUnaryExprAST(UnaryExprAST ast, Object o)
			throws CompilationException {
		return ast.op;
	}

	// BinExprAST
	public Object visitBinExprAST(BinExprAST ast, Object o)
			throws CompilationException {
		return ast.e1.visit(this, o);
	}

	// VarExprAST
	public Object visitVarExprAST(VarExprAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// EleExprAST
	public Object visitEleExprAST(EleExprAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}

	// CallExprAST
	public Object visitCallExprAST(CallExprAST ast, Object o)
			throws CompilationException {
		return ast.name;
	}
}
